package org.jeecg.modules.InveotoryCenter.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.InveotoryCenter.entity.InveotoryEntity;
import org.jeecg.modules.InveotoryCenter.entity.piciEntity;
import org.jeecg.modules.InveotoryCenter.service.InveotoryQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/InveotoryQuery")
public class InveotoryQueryController {

    @Autowired
    InveotoryQueryService service;


    /**
     * 库存查询
     * @param pageSize
     * @param pageNo
     * @return
     */
    @GetMapping("/list")
    public Result<?> InveotoryQuerylist(
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo
    ){
        Page<InveotoryEntity> page =new  Page<InveotoryEntity>(pageNo, pageSize);
        IPage<InveotoryEntity> pageList=service.getInveotoryQuerylist(page);

        if(pageList!=null){
            for (int i=0;i<pageList.getRecords().size();i++){
                pageList.getRecords().get(i).setSumCount(service.tongjiSum( pageList.getRecords().get(i).getId()));
            }
        }
        return Result.ok(pageList);
    }
    

    /**
     * 库存查询里的详情里的通过库存id查询批次
     */
    @GetMapping("/picilist")
    public Result<?> picilist(
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "id") String   merchandiseInventoryId

    ){
           Page<piciEntity> page=new  Page<piciEntity>(pageNo, pageSize);
          IPage<piciEntity> pageList=service.getpiciListBykucunId(page,merchandiseInventoryId);
        return Result.ok(pageList);
    }


    /**
     * 库存查询里的详情信息
     */
    @GetMapping("/kucundetail")
    public Result<?> kucundetail(
            @RequestParam(name = "id") String   merchandiseInventoryId,
            @RequestParam(name = "type") int   type
           // @RequestParam(name = "goodsCode") String   goodsCode
    ){
        InveotoryEntity entity = null;
        //0商品 1面料
        if(type==0){
            entity=service.getGoodsDetail(merchandiseInventoryId);
            entity.setSumCount(service.tongjiSum(merchandiseInventoryId));
        }else  if(type==1){
            entity=service.getFabricDetail(merchandiseInventoryId);
            entity.setSumCount(service.tongjiSum(merchandiseInventoryId));
        }

        return Result.ok(entity);
    }




}
